#include <stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#define FILE_NAME "log.txt"

//系统文件接口
void test_sys_file()
{
    //写入接口
    /* umask(0);
    int fd = open(FILE_NAME, O_WRONLY | O_CREAT | O_TRUNC, 0666);
    int cnt  = 5;
    char buffer[1024];
    while(cnt)
    {
        sprintf(buffer, "%s, %d\n", "hello sys", cnt--);
        write(fd, buffer, strlen(buffer));
    } */


    //读取接口
    /* int fd = open(FILE_NAME, O_RDONLY);
    char line[1024];
    ssize_t sz = read(fd, line, sizeof(line) - 1);
    line[sz] = 0; //把读取的数据变成字符串格式
    puts(line);
    close(fd); */

    //追加接口
    int fd = open(FILE_NAME, O_WRONLY | O_CREAT | O_APPEND);
    char buffer[1024];
    sprintf(buffer, "%s", "aaa\n");
    write(fd, buffer, strlen(buffer));
    close(fd);
}

int main()
{
    test_sys_file();
}